/**
 * Auto gen via dbpojo-gen.
 */
package com.us.usws.dao;

import java.util.List;

import net.iwsh.core.db.DBExecutor;
import net.iwsh.core.db.ext.DialectSyntaxParser;
import net.iwsh.core.db.ext.SQLWithParams;

import com.us.usws.model.domain.system.SchoolStage;
import com.us.usws.model.flat.system.DOSchoolStage;

/**
 * DAO class
 * @author robot
 */
public class SchoolStageDAO {

	/**
	 * Query SQLs
	 */
	private static final String SQL_GET_TOTAL_COUNT = "select count(*) from sys_school_stage";
	private static final String SQL_GET_ALL_SCHOOLSTAGES = "select * from sys_school_stage";
	private static final String SQL_GET_SCHOOLSTAGE_BY_PK = "select * from sys_school_stage where school_uid = ? and stage_dsid = ?";

	/**
	 * CUR SQLs
	 */
	private static final String SQL_INSERT_SCHOOLSTAGE = "insert into sys_school_stage(school_uid,stage_dsid) values (?,?)";
	private static final String SQL_DEL_SCHOOLSTAGE = "delete from sys_school_stage where school_uid=? and stage_dsid=?";

	/**
	 * DBExeutor
	 */
	private DBExecutor dbe = new DBExecutor();

	/**
	 * Get Count.
	 */
	public int getTotalCount() {
		return dbe.getCount(SQL_GET_TOTAL_COUNT);
	}

	/**
	 * Get all list.
	 */
	public List<SchoolStage> getAllSchoolStages() {
		return dbe.list(SQL_GET_ALL_SCHOOLSTAGES, SchoolStage.class);
	}

	/**
	 * Get all list by pagination.
	 */
	public List<SchoolStage> getSchoolStages(int start, int end) {
		SQLWithParams swp = DialectSyntaxParser.getParser().getPaginationSQLWithParams(SQL_GET_ALL_SCHOOLSTAGES, null, start, end);
		return dbe.list(swp.getSql(), SchoolStage.class, swp.getParams());
	}

	/**
	 * Get SchoolStage by primary key.
	 */
	public SchoolStage getSchoolStage(String schoolUid, Integer stageDsid) {
		SchoolStage s = dbe.load(SQL_GET_SCHOOLSTAGE_BY_PK, SchoolStage.class, schoolUid, stageDsid);
		return s;
	}

	/**
	 * Insert one row.
	 */
	public String insertSchoolStage(DOSchoolStage schoolStage) {
		dbe.execute(SQL_INSERT_SCHOOLSTAGE, schoolStage.getSchoolUid(), schoolStage.getStageDsid());
		return schoolStage.getSchoolUid();
	}

	/**
	 * Delete row by PK.
	 */
	public void deleteSchoolStage(String schoolUid, Integer stageDsid) {
		dbe.execute(SQL_DEL_SCHOOLSTAGE, schoolUid, stageDsid);
	}

}